package de.itagile.hypersphere

class EntityTemplate extends Template {
	
	String name
	String ePackage
	String table
	def fields
	def relationships
	def fieldTemplate
	def relationshipTemplate
	
	def root() {
		return [
			"package ${ePackage};",
	        "import javax.persistence.*;",
	        "@Entity",
	        '@Table(name = "' + table + '")',
	        "public class ${name} {",
	        	fields(),
	        	relationships(),
	        "}"
        ]
	}
	
	def relationships() {
		return [
		        forall(relationships, relationshipTemplate.rootRelationship())
        ]
	}
	
	def fields() {
		return [
			forall(fields, fieldTemplate.getField()),
	    	forall(fields, fieldTemplate.getGetter()),
	    	forall(fields, fieldTemplate.getSetter())
    	]
	}
	
	def start = {
		file (ePackage + '.' + name,
			[
		        root()
	        ]
		)
	}
}